package com.mao.crowd.controller;

import com.mao.crowd.api.MySQLRemoteService;
import com.mao.crowd.constant.CrowdConstant;
import com.mao.crowd.entity.po.OrderExample;
import com.mao.crowd.entity.vo.AddressVO;
import com.mao.crowd.entity.vo.MemberLoginVO;
import com.mao.crowd.entity.vo.OrderProjectVO;
import com.mao.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author: Administrator
 * @description:
 * @cteate 2021-06-28-21:14
 */
@Controller
public class OrderConsumerComtroller {

    @Autowired
    private MySQLRemoteService mySQLRemoteService;

    @RequestMapping("/confirm/return/info/{projectId}/{returnId}")
    public String returnConfirmInfo(@PathVariable("projectId") Integer projectId,
                                    @PathVariable("returnId") Integer returnId,
                                    HttpSession session){
        ResultEntity<OrderProjectVO> resultEntity = mySQLRemoteService.getOrderProjectVORemote(projectId,returnId);

        if (ResultEntity.SUCCESS.equals(resultEntity.getResult())){
            OrderProjectVO orderProjectVO = resultEntity.getData();
            // 为了保持orderProjectVO项目回报数据,放在session中
            session.setAttribute("orderProjectVO",orderProjectVO);
        }
        return "confirm-return";
    }

    @RequestMapping("/confirm/order/{returnCount}")
    public String showConfirmOrderInfo(@PathVariable("returnCount") Integer returnCount,
                                       HttpSession session){
        OrderProjectVO orderProjectVO = (OrderProjectVO) session.getAttribute("orderProjectVO");
        orderProjectVO.setReturnCount(returnCount);
        session.setAttribute("orderProjectVO",orderProjectVO);

        MemberLoginVO member = (MemberLoginVO) session.getAttribute(CrowdConstant.ATTR_NAME_LOGIN_MEMBER);
        Integer memberId = member.getId();
        // 查询现有收货地址数据
        ResultEntity<List<AddressVO>> resultEntity = mySQLRemoteService.getAddressVORemote(memberId);
        if (ResultEntity.SUCCESS.equals(resultEntity.getResult())){
            List<AddressVO> addressVOList = resultEntity.getData();
            session.setAttribute("addressVOList",addressVOList);
        }
        return "confirm-order";
    }

}
